import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;

public class DemoThree {
    public static void main(String[] args) {

        //案例3：上传本地文件到hdfs
        System.setProperty("hadoop.home.dir","D:\\code2\\hadoop-2.7.3");
        System.setProperty("HADOOP_USER_NAME","root");

        try {

            String url = "hdfs://192.168.75.11:9000";
            Configuration conf = new Configuration();
            FileSystem fileSystem = FileSystem.get(URI.create(url), conf);

            //本地的文件
            Path srcPath = new Path("D:\\17code\\17demo3.txt");
            //hdfs的路径
            Path destPath = new Path("/test/");
            //使用hadoop的copyFromLocafile
            fileSystem.copyFromLocalFile(srcPath, destPath);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
